package com.dense.kuiniu.floatcabinet.mvp.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ScreenUtils;
import com.dense.kuiniu.floatcabinet.R;
import com.dense.kuiniu.floatcabinet.mvp.manager.bord.Door;

import java.util.List;

/**
 * @author Administrator
 * @date 2020/11/20
 */
public class DialogDooroOpened extends Dialog {
    TextView tvDoors;

    public DialogDooroOpened(@NonNull Context context) {
        super(context);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_door_opened, null);
        tvDoors = view.findViewById(R.id.tv_doors);
        view.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        setContentView(view);
    }


    public void updateInfo(List<Door> doors) {
        if (tvDoors != null && doors != null) {
            StringBuilder info = new StringBuilder();
            for (Door door : doors) {
                info.append("门号:").append(door.getDoorNumber()).append(",");
            }
            if (info.length() > 0) {
                info = new StringBuilder(info.substring(0, info.length() - 1));
                tvDoors.setText(info.toString());
            }
        }
    }

    @Override
    public void show() {
        super.show();
        measureSize();
    }

    protected void measureSize() {
        Window dialogWindow = getWindow();
        if (dialogWindow != null) {
            dialogWindow.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.shape_transparent));
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.width = (int) (ScreenUtils.getScreenWidth() * 0.65); // 宽度
            lp.height = (int) (ScreenUtils.getScreenHeight() * 0.315); // 高度
            dialogWindow.setGravity(Gravity.CENTER);
            dialogWindow.setAttributes(lp);
            dialogWindow.setWindowAnimations(R.style.DialogOutAndInStyle);
        }
    }
}